/*
 * =====================================================================================
 *
 *       Filename:  debug.c
 *
 *    Description:  
 *
 *        Version:  1.0
 *        Created:  2019年04月26日 16时50分41秒
 *       Revision:  none
 *       Compiler:  gcc
 *
 *         Author:  YOUR NAME (), 
 *   Organization:  
 *
 * =====================================================================================
 */
#include "util_debug.h"

static int debug_switch = 1;

int get_debug_switch()
{
    return debug_switch;
}

void set_debug_switch(int switch_set)
{
    debug_switch = switch_set;
}

int debug_log(const char *fmt, ...)
{
    char *buff = NULL;
    va_list arg;
    va_start(arg, fmt);
    int ret = vasprintf(&buff, fmt, arg);
    va_end(arg);
    if(ret > 0 && buff) {
        syslog(LOG_INFO, "%s", buff);
        free(buff);
    }
    return ret;
}

int debug_err(const char *fmt, ...)
{
    va_list arg;
    va_start(arg, fmt);
    int ret = vfprintf(stderr, fmt, arg);
    va_end(arg);
    return ret;
}

int debug_print(const char *fmt, ...)
{
    if(debug_switch) {
        va_list arg;
        va_start(arg, fmt);
        int ret = vfprintf(stdout, fmt, arg);
        va_end(arg);
        return ret;
    }
    return 0;
}


